package com.woniuxy.house.provider;

import com.woniuxy.house.entity.Booking;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.jdbc.SQL;

@Slf4j
public class BookingSqlProvider {
    public String update(Booking booking){
        String sql=new SQL(){
            {
                UPDATE("house_booking");
                if(booking.getBookingTime()!=null){
                    SET("booking_time=#{bookingTime}");
                }
                if(booking.getLookTime()!=null){
                    SET("look_time=#{lookTime}");
                }
                if(booking.getName()!=null){
                    SET("name=#{name}");
                }
                if(booking.getStatus()!=null){
                    SET("status=#{status}");
                }
                if(booking.getUser()!=null){
                    SET("user_id=#{user.id}");
                }
                if(booking.getSource()!=null){
                    SET("source_id=#{source.id}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
        log.debug("SQL:{}",sql);
        return sql;
    }
}
